package com.example.arithmeticleetcode.leetcode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @program: arithmetic-leetcode
 * @description: 1189. “气球” 的最大数量
 * @author: FangZhen
 * @create: 2020-04-23 10:08
 **/
public class Demo07 {

    public static void main(String[] args) {
        System.out.println(maxNumberOfBalloons("nlaebolko"));
        System.out.println(maxNumberOfBalloons("loonbalxballpoon"));
        System.out.println(maxNumberOfBalloons("leetcode"));
        System.out.println(maxNumberOfBalloons("balon"));
    }

    public static int maxNumberOfBalloons(String text) {
        Map<Character, Integer> map = new HashMap<>();
        map.put('a', 0);
        map.put('b', 0);
        map.put('l', 0);
        map.put('o', 0);
        map.put('n', 0);
        for (char c : text.toCharArray()) {
            if (map.containsKey(c)) {
                map.put(c, map.getOrDefault(c, 0) + 1);
            }
        }
        int max = Integer.MAX_VALUE;
        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
            int i = entry.getValue();
            if ('l' == entry.getKey() || 'o' == entry.getKey()) {
                i = entry.getValue() / 2;
            }
            if (max > i) {
                max = i;
            }
        }
        return max;

    }
}
